import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/* Router Modules */
import componentsRouter from './modules/components'
import chartsRouter from './modules/charts'
import tableRouter from './modules/table'
import nestedRouter from './modules/nested'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    noCache: true                if set true, the page will no be cached(default is false)
    affix: true                  if set true, the tag will affix in the tags-view
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path(.*)',
        component: () => import('@/views/redirect/index')
      }
    ]
  },
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/auth-redirect',
    component: () => import('@/views/login/auth-redirect'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/error-page/404'),
    hidden: true
  },
  {
    path: '/401',
    component: () => import('@/views/error-page/401'),
    hidden: true
  },
  {
    path: '/',
    component: Layout,
    redirect: '/solutions'
  }
]

/**
 * asyncRoutes
 * the routes that need to be dynamically loaded based on user roles
 */
export const asyncRoutes = [
  {
    path: '/solutions',
    component: Layout,
    name: 'solutions',
    // redirect: '/solutions/lists',
    meta: {
      title: '解决方案',
      icon: 'table'
    },
    children: [
      {
        path: '',
        component: () => import('@/views/solutions/index'),
        name: 'lists',
        meta: { title: '方案列表' },
        hidden: true
      },
      {
        path: 'create',
        component: () => import('@/views/solutions/edit'),
        name: 'create',
        meta: { title: '编辑方案' },
        hidden: true
      },
      {
        path: 'edit/:id',
        component: () => import('@/views/solutions/edit'),
        name: 'edit',
        meta: { title: '编辑方案' },
        hidden: true
      },
      {
        path: 'medical',
        component: () => import('@/views/solutions/feature/medical'),
        name: 'medical',
        meta: { title: '新增项目背景' },
        hidden: true
      },
      {
        path: 'medical/:id',
        component: () => import('@/views/solutions/feature/medical'),
        name: 'medical',
        meta: { title: '编辑项目背景' },
        hidden: true
      },

      {
        path: 'feature',
        component: () => import('@/views/solutions/feature/feature'),
        name: 'feature',
        meta: { title: '解决方案描述' },
        hidden: true
      },
      {
        path: 'feature/:id',
        component: () => import('@/views/solutions/feature/feature'),
        name: 'feature',
        meta: { title: '解决方案描述' },
        hidden: true
      },

      {
        path: 'advantage',
        component: () => import('@/views/solutions/feature/advantage'),
        name: 'advantage',
        meta: { title: '方案优势' },
        hidden: true
      },
      {
        path: 'advantage/:id',
        component: () => import('@/views/solutions/feature/advantage'),
        name: 'advantage',
        meta: { title: '方案优势' },
        hidden: true
      },

      {
        path: 'product',
        component: () => import('@/views/solutions/feature/product'),
        name: 'product',
        meta: { title: '方案优势' },
        hidden: true
      },
      {
        path: 'product/:id',
        component: () => import('@/views/solutions/feature/product'),
        name: 'product',
        meta: { title: '方案优势' },
        hidden: true
      },

      {
        path: 'partner',
        component: () => import('@/views/solutions/feature/partner'),
        name: 'partner',
        meta: { title: '合作伙伴' },
        hidden: true
      },
      {
        path: 'partner/:id',
        component: () => import('@/views/solutions/feature/partner'),
        name: 'partner',
        meta: { title: '合作伙伴' },
        hidden: true
      },
    ]
  },
  {
    path: '/news',
    component: Layout,
    name: 'news',
    meta: { title: '新闻中心', icon: 'el-icon-news' },
    children: [
      {
        path: '',
        name: 'news-list',
        component: () => import('@/views/news-center'),
        meta: { title: '新闻列表' },
        hidden: true
      },
      {
        path: 'create',
        name: 'news-create',
        component: () => import('@/views/news-center/components/edit'),
        meta: { title: '新建新闻' },
        hidden: true
      },
      {
        path: 'edit',
        name: 'news-edit',
        component: () => import('@/views/news-center/components/edit'),
        meta: { title: '编辑新闻' },
        hidden: true
      },
      {
        path: 'edit/:id',
        name: 'news-edit',
        component: () => import('@/views/news-center/components/edit'),
        meta: { title: '编辑新闻' },
        hidden: true
      }
    ]
  },

  {
    path: '/product',
    component: Layout,
    name: 'product-service',
    meta: { title: '产品服务', icon: 'table' },
    children: [
      {
        path: '',
        component: () => import('@/views/product-service/index'),
        name: 'lists',
        // meta: { title: '服务列表' },
        hidden: true
      },
      {
        path: 'create',
        component: () => import('@/views/product-service/edit'),
        name: 'create',
        meta: { title: '编辑产品' },
        hidden: true
      },
      {
        path: 'edit/:id',
        component: () => import('@/views/product-service/edit'),
        name: 'edit',
        meta: { title: '编辑产品' },
        hidden: true
      },
      {
        path: 'medical',
        component: () => import('@/views/product-service/feature/medical'),
        name: 'medical',
        meta: { title: '新增项目背景' },
        hidden: true
      },
      {
        path: 'medical/:id',
        component: () => import('@/views/product-service/feature/medical'),
        name: 'medical',
        meta: { title: '编辑项目背景' },
        hidden: true
      },

      {
        path: 'feature',
        component: () => import('@/views/product-service/feature/feature'),
        name: 'feature',
        meta: { title: '解决问题' },
        hidden: true
      },
      {
        path: 'upData',
        component: () => import('@/views/product-service/feature/upData'),
        name: 'upData',
        meta: { title: '数字影像服务' },
        hidden: true
      },
      {
        path: 'feature/:id',
        component: () => import('@/views/product-service/feature/feature'),
        name: 'feature',
        meta: { title: '解决问题' },
        hidden: true
      },

      {
        path: 'advantage',
        component: () => import('@/views/product-service/feature/advantage'),
        name: 'advantage',
        meta: { title: '产品效益' },
        hidden: true
      },
      {
        path: 'advantage/:id',
        component: () => import('@/views/product-service/feature/advantage'),
        name: 'advantage',
        meta: { title: '产品效益' },
        hidden: true
      },

      {
        path: 'scene',
        component: () => import('@/views/product-service/feature/scene'),
        name: 'scene',
        meta: { title: '应用场景' },
        hidden: true
      },
      {
        path: 'scene/:id',
        component: () => import('@/views/product-service/feature/scene'),
        name: 'scene',
        meta: { title: '应用场景' },
        hidden: true
      }
    ]
  },

  {
    path: '/recruitment',
    component: Layout,
    name: 'recruitment',
    redirect: '/recruitment/careers',
    meta: { title: '人才招聘', icon: 'peoples' },
    children: [
      {
        path: 'organization',
        component: () => import('@/views/recruitment/organization'),
        name: 'organization',
        meta: { title: '组织架构' }
      },
      {
        path: 'careers',
        component: () => import('@/views/recruitment/careers'),
        name: 'careers',
        meta: { title: '人才招聘' }
      },
      {
        path: 'message',
        component: () => import('@/views/recruitment/message'),
        name: 'message',
        meta: { title: '招聘信息' },
        hidden: true
      },
      {
        path: 'detail',
        component: () => import('@/views/recruitment/detail'),
        name: 'detail',
        meta: { title: '查看招聘信息' },
        hidden: true
      }
    ]
  },

  {
    path: '/partner',
    component: Layout,
    name: 'partner',
    meta: { title: '合作伙伴', icon: 'peoples' },
    children: [
      {
        path: '',
        component: () => import('@/views/partner'),
        name: 'partner',
        meta: { title: '合作伙伴' },
        hidden: true
      }
    ]
  },

  {
    path: '/system-setting',
    component: Layout,
    name: 'system-setting',
    meta: { title: '关于云慧', icon: 'peoples' },
    children: [
      {
        path: '',
        component: () => import('@/views/system-setting'),
        name: 'system-setting',
        meta: { title: '关于云慧' },
        hidden: true
      }
    ]
  },

  {
    path: '/user',
    component: Layout,
    name: 'user',
    meta: { title: '用户管理', icon: 'peoples' },
    children: [
      {
        path: '',
        component: () => import('@/views/user'),
        name: 'user',
        meta: { title: '用户管理' },
        hidden: true
      }
    ]
  },

  {
    path: '/contact-info',
    component: Layout,
    name: 'contact-info',
    meta: { title: '联系信息', icon: 'peoples' },
    children: [
      {
        path: '',
        component: () => import('@/views/contact-info'),
        name: 'contact-info',
        meta: { title: '联系信息' },
        hidden: true
      }
    ]
  },

  {
    path: '/banner',
    component: Layout,
    name: 'banner',
    meta: { title: '图片管理', icon: 'peoples' },
    children: [
      {
        path: '',
        component: () => import('@/views/banner'),
        name: 'banner',
        meta: { title: '图片管理' },
        hidden: true
      }
    ]
  },



  // {
  //   path: '/Home',
  //   component: Layout,
  //   redirect: '/Home/hospital',
  //   name: 'home',
  //   meta: {
  //     title: '解决方案',
  //     icon: 'table'
  //   },
  //   children: [
  //     {
  //       path: 'hospital',
  //       component: () => import('@/views/home/index'),
  //       name: 'hospital',
  //       meta: { title: '智慧医院', icon: 'dashboard', affix: true }
  //     },
  //     {
  //       path: 'template',
  //       component: () => import('@/views/home/template'),
  //       name: 'template',
  //       meta: { title: '智慧医共体', icon: 'dashboard', affix: true }
  //     },
  //     {
  //       path: 'equipment1',
  //       component: () => import('@/views/home/equipment'),
  //       name: 'equipment1',
  //       meta: { title: '城市健康', icon: 'dashboard', affix: true }
  //     },
  //     {
  //       path: 'equipment2',
  //       component: () => import('@/views/home/equipment'),
  //       name: 'equipment2',
  //       meta: { title: '舒心就医', icon: 'dashboard', affix: true }
  //     },
  //     {
  //       path: 'synchronization',
  //       component: () => import('@/views/home/synchronization'),
  //       name: 'synchronization',
  //       hidden: true,
  //       meta: { title: '同步', icon: 'dashboard', affix: true }
  //     }
  //   ]
  // },
  // {
  //   path: '/version',
  //   component: Layout,
  //   name: 'version',
  //   meta: { title: '产品服务', icon: 'table' },
  //   redirect: '/version/upgrade',
  //   children: [
  //     {
  //       path: 'upgrade',
  //       component: () => import('@/views/version/upgrade'),
  //       name: 'upgrade',
  //       meta: { title: '数字影视服务', icon: 'dashboard', affix: true }
  //     },
  //     {
  //       path: 'history',
  //       component: () => import('@/views/version/history'),
  //       name: 'history',
  //       meta: { title: '数字云平台', icon: 'dashboard', affix: true }
  //     },
  //     {
  //       path: 'version1',
  //       component: () => import('@/views/version/version'),
  //       name: 'version1',
  //       meta: { title: '互联网医院', icon: 'dashboard', affix: true }
  //     },
  //     {
  //       path: 'version2',
  //       component: () => import('@/views/version/version'),
  //       name: 'version2',
  //       meta: { title: '远程医疗平台', icon: 'dashboard', affix: true }
  //     },
  //     {
  //       path: 'version3',
  //       component: () => import('@/views/version/version'),
  //       name: 'version3',
  //       meta: { title: '医疗监督平台', icon: 'dashboard', affix: true }
  //     }
  //   ]
  // },
  // {
  //   path: '/example',
  //   component: Layout,
  //   redirect: '/example/list',
  //   name: 'Example',
  //   meta: {
  //     title: 'Example',
  //     icon: 'el-icon-s-help'
  //   },
  //   children: [
  //     {
  //       path: 'create',
  //       component: () => import('@/views/example/create'),
  //       name: 'CreateArticle',
  //       meta: { title: 'Create Article', icon: 'edit' }
  //     },
  //     {
  //       path: 'edit/:id(\\d+)',
  //       component: () => import('@/views/example/edit'),
  //       name: 'EditArticle',
  //       meta: { title: 'Edit Article', noCache: true, activeMenu: '/example/list' },
  //       hidden: true
  //     },
  //     {
  //       path: 'list',
  //       component: () => import('@/views/example/list'),
  //       name: 'ArticleList',
  //       meta: { title: 'Article List', icon: 'list' }
  //     }
  //   ]
  // },

  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
